'''
Created on Jun 2, 2009

@author: mkiyer
'''
 
from optparse import OptionParser
from veggie.parser.bedparser import BEDParser, BEDAnnotation
import sys

def filter_neg_positions(a):
    if a.chromStart < 0:
        print >>sys.stderr, 'found bed line < 0', a
        a.chromStart = 0

if __name__ == '__main__':
    # setup command line parser
    usage = "usage: %prog [options] infile outfile"
    
    # parse command line
    optparser = OptionParser()
    (options, args) = optparser.parse_args()
    # check options, args
    if len(args) < 1:
        optparser.error('No input file specified')
    # setup input and output files
    infhd = open(args[0])
    if len(args) < 2:
        outfhd = sys.stdout
    else:
        outfhd = open(args[1], 'w')

    # apply filter
    # TODO: add command line options for different filters
    BEDParser.filterFile(infhd, outfhd, filterfunc=filter_neg_positions)
